package com.risesoftware.battlebugs;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.util.Log;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BattleShipEnnemyActivity extends BattleShip {

	int timerSecondsLimit;
	private Handler timeHandler = new Handler();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.game_top);
		this.resetBoard();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	} 
	
	@Override
	protected void onResume() {
		super.onResume();		
		this.startTimer();
		this.drawBoatStatus();
	}

	private void drawBoatStatus()
	{		
		LinearLayout l = (LinearLayout)this.findViewById(R.id.linearLayout1);
		
		for(int i = 0 ; i < this.boats.size() ; i++)
		{

		}
	}
	
	public void onTimeOut()
	{
				
	}
	
	private void DisplayWin()
	{
		TextView result = (TextView)this.findViewById(R.id.result);
		result.setText(R.string.win);
	}
	
	private void DisplayLose()
	{
		TextView result = (TextView)this.findViewById(R.id.result);
		result.setText(R.string.lose);				
	}
	
	private void startTimer() 
	{		
		MyTimer timer = new MyTimer();
		timer.act = this;	
		
		Log.d("start", "timer");
		
		timeHandler.post(timer);
	}
}

class MyTimer implements Runnable
{
	public BattleShipEnnemyActivity act ;	 
	
	public void run() {

		TextView timerView = (TextView)this.act.findViewById(R.id.timer);
				
		Calendar c = Calendar.getInstance();
		int seconds = c.get(Calendar.SECOND);
		int minutes = c.get(Calendar.MINUTE);

		long endTime = c.getTimeInMillis() + this.act.timerSecondsLimit * 1000;

		while (c.getTimeInMillis() < endTime) 
		{
			timerView.setText("" + minutes + ":" + (seconds < 10 ? "0" : "") + seconds);
			Log.d("timer", "" + minutes + ":" + (seconds < 10 ? "0" : "") + seconds);
		}		
		act.onTimeOut();
	}
}
	
 